package com.bj58.ecdata.dashboard.constant;

import net.sf.json.JSONArray;

import com.bj58.ecdata.dashboard.dbentity.IncomeSource_APP;
import com.bj58.ecdata.dashboard.dbentity.IncomeSource_M;
import com.bj58.ecdata.dashboard.dbentity.IncomeSource_PC;

public enum IncomePlatConst {

	PC,M,APP;
	public static final JSONArray indexList_EN = JSONArray.fromObject("['cash', 'pv', 'adpv', 'disp', 'click', 'acp','pvr', 'asn', 'cpm1', 'cpm2', 'cpm3', 'ctr1', 'ctr2', 'ctr3','realization_rate']");
	public static final JSONArray indexList_CN = JSONArray.fromObject("['现金消费', 'PV', 'ADPV', '展现', '点击','ACP', 'PVR', 'ASN', 'CPM1', 'CPM2', 'CPM3', 'CTR1', 'CTR2', 'CTR3','变现率']");
	public static final JSONArray soruce1List_PC = JSONArray.fromObject("['站内','直接访问','站外引荐','付费浏览器','58联盟','付费其他','广告系列','站外其他','SEM','SEO','sou','other','其他']");
	public static final JSONArray soruce1List_M = JSONArray.fromObject("['站内','58联盟','付费其他','付费浏览器','广告系列','站外其他','SEM','SEO','sou','other','其他']");
	public static final JSONArray soruce1List_APP = JSONArray.fromObject("['站内','58联盟','站外其他']");


	/* 分平台趋势图查询 */
	private static final String PATTEN_Plat = "business_name='%s' AND product_type='%s' AND stat_type='%s' ";
	public static String getPlatCol(String dateGroup, String index) {
		return dateGroup+","+index+",platform";
	}
	
	public static String getPlatCon(String stat_type, String businessName,String product_type){
		return String.format(PATTEN_Plat, businessName, product_type, stat_type);
	}

	
	
	/**
	 * 分平台 表格数据查询条件
	 * @param dateGroup
	 * @return
	 */
	private static final String PLATFORM_CON_Table = "%s='%s' AND business_name='%s' AND stat_type='%s' and product_type='%S'";
	
	public static String getCityProTableCon(String dateGroup, String stat_type,
			String dateVal, String businessName, String product) {
		return String.format(PLATFORM_CON_Table, dateGroup,dateVal, businessName, stat_type,product);
	}
	
	/**
	 * 0级来源查询列---饼图
	 * @param dateGroup
	 * @return
	*/
	private static final String SOURCE_PIE_CON = "business_name='%s' AND stat_type='day' AND stat_date >='%s' AND stat_date<='%s' AND source!='all' AND source1='all' GROUP BY source";

	public static String getSourcePieCols() {
		return "source,sum(cash)/count(distinct stat_date) as cash";
	}
	
	public static String getSourcePieCon(String businessName, String beginDate,String endDate) {
		return String.format(SOURCE_PIE_CON, businessName, beginDate,endDate);
	}
	
	/**
	 * 1级来源查询列
	 * @param dateGroup
	 * @return
	*/
	private static final String SOURCE1_PIE_CON = "business_name='%s' AND stat_type='day' AND stat_date >='%s' AND stat_date<='%s' AND source='%s' AND source1!='all' and source2='all' GROUP BY source1";

	public static String getSource1PieCols() {
		return "source1,sum(cash)/count(distinct stat_date) as cash";
	}
	
	public static String getSource1PieCon(String businessName,String source, String beginDate,String endDate) {
		return String.format(SOURCE1_PIE_CON, businessName, beginDate,endDate, source);
	}

	/**
	 * 2级来源查询列
	 * @param dateGroup
	 * @return
	*/
	private static final String SOURCE2_PIE_CON = "business_name='%s' AND stat_type='day' AND stat_date >='%s' AND stat_date<='%s' AND source1='%s' AND source2!='all' GROUP BY source2";

	public static String getSource2PieCols() {
		return "source2,sum(cash)/count(distinct stat_date) as cash";
	}
	
	public static String getSource2PieCon(String businessName,String source, String beginDate,String endDate) {
		return String.format(SOURCE2_PIE_CON, businessName, beginDate,endDate, source);
	}
	
	/**收入看板流量来源实体类
	 * @return
	 * @author zhaoxiang 2015-03-26
	 */
	public Class<?> getSourceBeanCls() {
		switch (this) {
			case PC:
				return IncomeSource_PC.class;
			case M:
				return IncomeSource_M.class;
			case APP:
				return IncomeSource_APP.class;
			default:
				return null;
		}
	}

	/**
	 * 0级来源查询列---曲线图
	 * @param dateGroup
	 * @return
	*/
	private static final String SOURCE_Line_CON = "business_name='%s' AND stat_type='%s' AND source1='all'";
	
	public static String getSourceLineCols(String dateGroup,String index) {
		return String.format("%s,source, %s",dateGroup, index);
	}
	
	public static String getSourceLineCon(String businessName,String stat_type) {
		return String.format(SOURCE_Line_CON, businessName,stat_type);
	}
	
	/**
	 * 1级来源查询列---曲线图
	 * @param dateGroup
	 * @return
	*/
	private static final String SOURCE1_Line_CON = "business_name='%s' AND stat_type='%s' AND source='%s' AND source1 in('%s') and source2='all'";
	
	public static String getSource1LineCols(String dateGroup,String index) {
		return String.format("%s,source1, %s",dateGroup, index);
	}
	
	public static String getSource1LineCon(String businessName,String stat_type, String source,String source1s) {
		return String.format(SOURCE1_Line_CON, businessName,stat_type, source,source1s);
	}
	/**
	 * 2级来源查询列---曲线图
	 * @param dateGroup
	 * @return
	*/
	private static final String SOURCE2_Line_CON = "business_name='%s' AND stat_type='%s' AND source1='%s' AND source2 in('%s')";
	
	public static String getSource2LineCols(String dateGroup,String index) {
		return String.format("%s,source2, %s",dateGroup, index);
	}
	
	public static String getSource2LineCon(String businessName,String stat_type, String source1,String source2s) {
		return String.format(SOURCE2_Line_CON, businessName,stat_type, source1,source2s);
	}
	
	
	

	/**
	 * 0级来源查询条件--- 表格
	 * @param dateGroup
	 * @return
	*/
	private static final String SOURCE_TAB_CON = "%s='%s' AND business_name='%s' AND stat_type='%s' AND source1='all'";
	
	public static String getSourceTabCon(String businessName,String stat_type,String dateGroup, String dateVal) {
		return String.format(SOURCE_TAB_CON,dateGroup,dateVal, businessName,stat_type);
	}
	
	/**
	 * 1级来源查询条件--- 表格
	 * @param dateGroup
	 * @return
	*/
	private static final String SOURCE1_TAB_CON = "%s='%s' AND business_name='%s' AND stat_type='%s' AND source='%s' AND source1 in('%s') and source2='all'";
	
	public static String getSource1TabCon(String businessName,String stat_type,String dateGroup, String dateVal,String source,String source1s) {
		return String.format(SOURCE1_TAB_CON,dateGroup,dateVal, businessName,stat_type,source,source1s);
	}
	
	/**
	 * 2级来源查询条件--- 表格
	 * @param dateGroup
	 * @return
	*/
	private static final String SOURCE2_TAB_CON = "%s='%s' AND business_name='%s' AND stat_type='%s' AND source1='%s' AND source2 in('%s')";
	
	public static String getSource2TabCon(String businessName,String stat_type,String dateGroup, String dateVal,String source1,String source2s) {
		return String.format(SOURCE2_TAB_CON,dateGroup,dateVal, businessName,stat_type,source1,source2s);
	}
	
}
